package com.it.data_stack.leetCode;

import com.it.data_stack.LinkListStack;

/**
 * @author: Coke
 * @DateTime: 2023/06/11/21:23
 * 有效的括号
 **/
public class E01LeetCode20 {
    public static boolean examine (String val) {
        int len = val.length();
        LinkListStack<Character> stack = new LinkListStack<Character>(10);
        for (int i = 0; i < len; i++) {
            char c = val.charAt(i);
            if (c == '(') {
                stack.push(')');
            } else if (c == '{') {
                stack.push('}');
            } else if (c == '[') {
                stack.push(']');
            } else if (! stack.isEmpty() && c != stack.pop()) {
                return false;
            }
        }
        if (stack.isEmpty()) {
            return true;
        }
        return false;
    }
}
